Next: Moving by Defuns, Up: Defuns [Contents][Index]
Many programming-language modes assume by default that any opening delimiter found at the left margin is the start of a top-level definition, or defun. Therefore, don’t put an opening delimiter at the left margin unless it should have that significance. For instance, never put an open-parenthesis at the left margin in a Lisp file unless it is the start of a top-level list.
The convention speeds up many Emacs operations, which would otherwise have to scan back to the beginning of the buffer to analyze the syntax of the code.
If you don’t follow this convention, not only will you have trouble when you explicitly use the commands for motion by defuns; other features that use them will also give you trouble. This includes the indentation commands (see Program Indent) and Font Lock mode (see Font Lock).
The most likely problem case is when you want an opening delimiter at the start of a line inside a string. To avoid trouble, put an escape character (‘\’, in C and Emacs Lisp, ‘/’ in some other Lisp dialects) before the opening delimiter. This will not affect the contents of the string, but will prevent that opening delimiter from starting a defun. Here’s an example:
(insert "Foo: \(bar) ")
To help you catch violations of this convention, Font Lock mode highlights confusing opening delimiters (those that ought to be quoted) in bold red.
If you need to override this convention, you can do so by
setting the variable
open-paren-in-column-0-is-defun-start. If this user
option is set to t (the default), opening
parentheses or braces at column zero always start defuns. When it
is nil, defuns are found by searching for parens or
braces at the outermost level.
Usually, you should leave this option at its default value of
t. If your buffer contains parentheses or braces in
column zero which don’t start defuns, and it is somehow
impractical to remove these parentheses or braces, it might be
helpful to set the option to nil. Be aware that this
might make scrolling and display in large buffers quite sluggish.
Furthermore, the parentheses and braces must be correctly matched
throughout the buffer for it to work properly.
Next: Moving by Defuns, Up: Defuns [Contents][Index]